﻿from api.base_api import BaseApi


class PermissionApi(BaseApi):

    _yaml_path = "../datas/request_data/permission_api.yaml"

    def get_select_corp(self, env, token):
        """
        获取登录用的的医院医联体子系统
        :param env: 环境
        :param token: basic-token
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        data = self.yaml_read(self._yaml_path, 'get_select_corp')
        return self.send(data)

    def user_redirect(self, env, token, sys_code):
        """
        登录用户跳转
        :param env: 环境
        :param token: basic-token
        :param sys_code: 模块id？
        :return:
        """
        self._params['sys_code'] = sys_code
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        data = self.yaml_read(self._yaml_path, 'user_redirect')
        return self.send(data)

    def get_system_parent_resource(self, env, token, sys_code):
        """
        接口跳转到内部子系统
        :param env: 环境
        :param token: basic-token
        :param sys_code:
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['sys_code'] = sys_code
        data = self.yaml_read(self._yaml_path, 'get_system_parent_resource')
        return self.send(data)

    def change_password(self, env, token, new_password, old_password):
        """
        修改密码
        :param token:basic-token
        :param env:环境
        :param new_password: 新密码
        :param old_password: 旧密码
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['new_password'] = new_password
        self._params['old_password'] = old_password
        data = self.yaml_read(self._yaml_path, 'change_password')
        return self.send(data)

    def get_user_permission_union(self, env, token):
        """
        获取医联体
        :param env: 环境
        :param token: basic-token
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        data = self.yaml_read(self._yaml_path, 'get_user_permission_union')
        return self.send(data)

    def get_user_permission_corp(self, env, token, union_id):
        """
        获取用户权限医院
        :param token:basic-token
        :param env:uat
        :param union_id: 医联体编号
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['union_id'] = union_id
        data = self.yaml_read(self._yaml_path, 'get_user_permission_corp')
        return self.send(data)

    def switch_corp_or_union(self, env, token, key, is_union_key, sys_code):
        """
        切换登录的医联体或医院
        :param token:basic-token
        :param env:uat
        :param key: is_union_key=true key =#{unionId} isUnionKey=false key =医院的id不是corpId注意
        :param is_union_key:true or false
        :param sys_code:门诊医院管理传outpatient,平台管理传basic
        :return:ResponseBody
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['key'] = key
        self._params['is_union_key'] = is_union_key
        self._params['sys_code'] = sys_code
        data = self.yaml_read(self._yaml_path, 'switch_corp_or_union')
        return self.send(data)

    def switch_parent_tab(self, env, token, menu_id, sys_code):
        """
        切换一级页面
        :param token:basic-token
        :param env:环境
        :param menu_id: 一级菜单id
        :param sys_code: 门诊医院管理传outpatient,平台管理basic
        :return:ResponseBody
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['menu_id'] = menu_id
        self._params['sys_code'] = sys_code
        data = self.yaml_read(self._yaml_path, 'switch_corp_or_union')
        return self.send(data)
